package com.weiyuwqj.server.task;

import com.weiyuwqj.api.constant.Global;
import com.weiyuwqj.api.constant.ItemStatus;
import com.weiyuwqj.api.model.BusAssetPackagePlan;
import com.weiyuwqj.api.service.BusAssetPackagePlanService;
import com.weiyuwqj.api.service.SysConfigParameterService;
import com.weiyuwqj.server.auto.BusItemAutoInvest;
import com.weiyuwqj.server.mapper.BasAssetsPackageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * Created by zhoufw on 2017/4/5.
 */
@Component
public class DayPlanReleaseTask {

    @Autowired
    BusAssetPackagePlanService busAssetPackagePlanService;
    @Autowired
    SysConfigParameterService configParameterService;
    @Autowired
    BusItemAutoInvest autoInvest;
    @Autowired
    BasAssetsPackageMapper packageMapper;

//    @Scheduled(cron = "0 0 0 * * ?")//每天凌晨0点执行
//    public void planRelease() {
//        //提前发布时间差
//        String time = Global.getAssetPlanReleaseDay();
//        //当前系统时间
//        Date date = new Date();
//        //获取下一期要发布的  只查询10条 目前考虑数据量比较小所以只查10条
//        List<BusAssetPackagePlan> list = busAssetPackagePlanService.getPlanList();
//        for (int i = 0; i < list.size(); i++) {
//            BusAssetPackagePlan busAssetPackagePlan = list.get(i);
//            //获取上期还款时间
//            Date beforetime = busAssetPackagePlan.getBeforeRepayTime();
//            long days = (date.getTime() - beforetime.getTime()) / (1000 * 60 * 60 * 24);
//            if (days <= Integer.valueOf(time)) { //如果上期还款时间和当前时间差值小于等于一天 则提前发布
//                autoInvest.basAssetsPackageMatchingAutoRule(busAssetPackagePlan);
//                busAssetPackagePlan.setStatus(ItemStatus.IN_THE_INVESTMENT);
//                busAssetPackagePlan.setReleaseTime(new Date());
//                busAssetPackagePlanService.updateNotNull(busAssetPackagePlan);
//            }
//        }
//    }
}
